package vek.ObjectCreation;

import java.util.ArrayList;
import vek.Objects.Addresse;
import vek.Objects.Openinghours;
import vek.Objects.POI;
import vek.Objects.Product;
import vek.XML.parsedObjects.ParsedObjectInterface;
import vek.XML.parsedObjects.ParsedAddresse;
import vek.XML.parsedObjects.ParsedOpeninghours;
import vek.XML.parsedObjects.ParsedProduct;

/**
 *  A class for creating POI objects from ParsedPOI objects
 * @author Christian, Michal og Jakob (Hold 1, gruppe 2)
 */
public class ObjectCreator {
    
    /**
     * Creates all the POI objects based on the ParsedObjects given
     * @param allObjects the ParsedObjectInterface objects which are to be used to create the POI objects
     */
    
    public ObjectCreator(ArrayList<ArrayList<ParsedObjectInterface>> allObjects)
    {
        createAllPOIObjects(allObjects);
    }
    
    /**
     * creates all the POI objects by calling the getAsPOI method in the ParsedIObjectInterface class.
     * <p>
     * NOTE: the getAsPOI method is different depending on which type of ParsedPOI object is used.
     * The specific types of ParsedPOI objects have their own implementation of the getAsPOI method, and creates different objects.
     * Thus a ParsedRestaurant will make a Restaurant and a ParsedMuseum will make a Museum but both will be polymorphed into POI objects
     * 
     * @param allObjects the ParsedObjectInterface POIs which are to be used to create the POI objects
     * @return an ArrayList of all the POIs created
     */
    
    public ArrayList<POI> createAllPOIObjects(ArrayList<ArrayList<ParsedObjectInterface>> allObjects)
    {
        ArrayList<POI> allPOIObjects = new ArrayList<POI>();
        
        for(int i = 0; i < allObjects.size(); i++)
        {
           for(int n = 0; n < allObjects.get(i).size(); n++)
            {
                allPOIObjects.add( allObjects.get(i).get(n).getAsPOI() );
            }
        }
        return allPOIObjects;
    }
    
    /**
     * Static method to create an Addresse, does this by giving the ParsedAddresse to the Addresse constructor.
     * @param pa the ParsedAddresse which the Addresse is to be created from
     * @return Addresse based on the ParsedAddresse
     */
    
    public static Addresse createAddresse(ParsedAddresse pa)
    {
        return new Addresse(pa);
    }
    
    /**
     * Static method for create the Openinghours, does this by giving the ParsedOpeninghours to the Openinghours constructor.
     * @param poh
     * @return a new Openinghours object
     */
    public static Openinghours createOpeninghours(ParsedOpeninghours poh)
    {
        return new Openinghours(poh);
    }
    
    /**
     * Static method to create a Product, does this by giving the ParsedProduct to the Product constructor.
     * @param pp the ParsedProduct which the Product is to be created from
     * @return Product based on the ParsedProduct
     */
    
    public static Product createProduct(ParsedProduct pp)
    {
        return new Product(pp);
    }
    
    /**
     * creates an ArrayList of products based on multiple Parsed Products.
     * @param alPP an ArrayList containing ParsedProducts
     * @return an ArrayList containing Products based on the ParsedProducts
     */
    
    public static ArrayList<Product> createArrayListWithProducts(ArrayList<ParsedProduct> alPP)
    {
        ArrayList<Product> returnedAL = new ArrayList<Product>();
        for(int i = 0; i < alPP.size(); i++)
        {
            returnedAL.add(createProduct(alPP.get(i)));
        }
        return returnedAL;
    }

}
